# -*- shell-script -*-

# 30dmidecode - Get hardware info using dmidecode

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2003, 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 30dmidecode,v 1.1 2006/04/11 18:38:28 emunson Exp $

dmidecode=$(type -p dmidecode)
[ -n "$dmidecode" ] || return 0

# Blacklist - dmidecode seems broken on x86_64.
[ $(uname -m) = "x86_64" ] && return 0

######################################################################

db_initialise_functions="${db_initialise_functions} db_initialise_dmidecode"

# Why not use:
#  dmidecode -s system-serial-number
#  dmidecode -s system-product-name
# Those options are new!

db_initialise_dmidecode ()
{
    local line type
    "$dmidecode" | \
    while read line ; do
	case "$line" in
	    Handle*)
		case "${line#Handle }" in
		    0x0001*)
			type="system"
			;;
		    0x0006*)
			type="processor"
			;;
		    0x0008*|0x0009*)
			type="memory"
			;;
		    *)
			type="other"
		esac
		;;
	    Serial\ Number*)
                case "$type" in
		    system)
			local f="${db_misc_dir}/serial"
			local rest="${line#Serial Number: }"
			[ -n "$rest" -a ! -f "$f" ] && echo "$rest" >"$f"
			;;
		esac
		;;
	    Product\ Name*)
                case "$type" in
		    system)
			local f="${db_misc_dir}/model"
			local rest="${line#Product Name: }"
			[ -n "$rest" -a ! -f "$f" ] && echo "$rest" >"$f"
			;;
		esac
		;;
	esac
    done

}
